package 题目集.图.最短路;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;
//https://www.dotcpp.com/oj/contest6239_problem1.html
public class Floyd {
    static int n;
    static short[][] dis;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dis = new short[n + 1][n + 1];
        for (int i = 1; i < n; i++) {
            short from = sc.nextShort();
            short to = sc.nextShort();
            short w = sc.nextShort();
            dis[from][to] = w;
            dis[to][from] = w;
        }
        floyd();
        int max = 0;
        for (short[] d : dis) {
            for (short i : d) {
                max = Math.max(max, i);
            }
        }
        long len = (max + 1L) * max / 2;

        System.out.println(max * 10L + len);
    }

    public static void floyd() {
        for (int i = 1; i <= n; i++) {    //中转点
            for (int j = 1; j <= n; j++) {    //起点
                for (int k = 1; k <= n; k++) {    //终点
                    if (j == k || dis[j][i] == 0 || dis[i][k] == 0) continue;
                    if (dis[j][k] > dis[j][i] + dis[i][k] || dis[j][k] == 0) {
                        dis[j][k] = (short) (dis[j][i] + dis[i][k]);
                    }
                }
            }
        }
    }
}
